import java.util.ArrayList;
import java.util.List;

public class utils
{
    public static <T> List<T> typeConversion(Object obj, Class<T> tClass)
    {
        List<T> list = new ArrayList<>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                list.add(tClass.cast(o));
            }
        }
        return list;
    }

    public static String getQualifiedId(SelectorExpr expr)
    {
        return expr.expr.name + "." + expr.sel.name;
    }

    public static String getCombinedId(Id id1, Id id2)
    {
        return id1.name + "." + id2.name;
    }

    public static boolean isQI(SelectorExpr selectorExpr)
    {
        return selectorExpr.expr != null && ((ScopeObject)((Id)selectorExpr.expr).object).kind == ScopeObject.KIND.Pkg;
    }

    public static Field findStructField(StructExpr structExpr, String selName)
    {
        for(Field field : structExpr.fields)
        {
            if(field.id.name.equals(selName))
                return field;
        }
        return null;
    }
}
